import 'package:flutter/material.dart';
import 'package:flutter_basic_learning/widgets/CommonHeader.dart';

import '../utils/CommonWidget.dart';

class ImageWidget extends StatelessWidget {
  const ImageWidget({super.key});
  //加载网络图片
  Widget loadNetworkImage() {
    Widget content = Image.network(
        'https://ts1.tc.mm.bing.net/th/id/OIP-C.7kSGRwe_IJg61dyveatBvgHaE8?w=242&h=211&c=8&rs=1&qlt=90&o=6&cb=thwsc4&dpr=1.5&pid=3.1&rm=2',
        fit: BoxFit.cover);
    content = SizedBox(
      width: 150,
      height: 150,
      child: content,
    );
    return content;
  }

  //
  // //加载本地图片
  // loadLocalImage(String imageUrl){
  //   Widget body = Image.asset(imageUrl,fit:BoxFit.cover);
  //   body = SizedBox(
  //     width: 150,
  //     height:150,
  //     child: body,
  //   );
  //   return body;
  // }
  //
  //标题描述
  Widget desc(String text) {
    Widget content =
        Text(text, style: const TextStyle(color: Colors.white, fontSize: 20));
    content = Center(child: content);
    content = Container(
      width: double.infinity,
      height: 40,
      decoration: const BoxDecoration(
        color: Colors.blueGrey,
      ),
      child: content,
    );

    return content;
  }

  //空白
  Widget blank(double height) {
    Widget content = SizedBox(height: height);
    return content;
  }

  Widget body() {
    Widget content = Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          //   加载网络图片
          desc('1.加载网络图片'),
          loadNetworkImage(),
          blank(20),
          desc('2.加载本地图片'),
          loadLocalImage('images/panda.png'),
        ]);
    content = SizedBox.expand(child: content);
    return content;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(appBar: const CommonHeader(title: '加载图片'), body: body());
  }
}
